package com.ruoyi.web.service.incomeexpense.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.domain.incomeexpense.ZQEmail;
import com.ruoyi.web.mapper.incomeexpense.ZQEmailMapper;
import com.ruoyi.web.service.incomeexpense.IZQEmailService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;


/**
 * 邮箱发送记录Service业务层处理
 * 
 * @author zq
 * @date 2024-01-13
 */
@Service
public class ZQEmailServiceImpl implements IZQEmailService
{

    private final ZQEmailMapper zQEmailMapper;

    public ZQEmailServiceImpl(ZQEmailMapper zQEmailMapper) {
        this.zQEmailMapper = zQEmailMapper;
    }

    /**
     * 查询邮箱发送记录
     * 
     * @param id 邮箱发送记录主键
     * @return 邮箱发送记录
     */
    @Override
    public ZQEmail selectZQEmailById(Long id)
    {
        return zQEmailMapper.selectZQEmailById(id,SecurityUtils.getUserId());
    }

    /**
     * 查询邮箱发送记录列表
     * 
     * @param zQEmail 邮箱发送记录
     * @return 邮箱发送记录
     */
    @Override
    public List<ZQEmail> selectZQEmailList(ZQEmail zQEmail)
    {
        zQEmail.setUserId(SecurityUtils.getUserId());
        return zQEmailMapper.selectZQEmailList(zQEmail);
    }

    /**
     * 新增邮箱发送记录
     * 
     * @param zQEmail 邮箱发送记录
     * @return 结果
     */
    @Override
    public int insertZQEmail(ZQEmail zQEmail)
    {
        return zQEmailMapper.insertZQEmail(zQEmail);
    }

    /**
     * 修改邮箱发送记录
     * 
     * @param zQEmail 邮箱发送记录
     * @return 结果
     */
    @Override
    public int updateZQEmail(ZQEmail zQEmail)
    {
        zQEmail.setUpdateTime(DateUtils.getNowDate());
        return zQEmailMapper.updateZQEmail(zQEmail);
    }

    /**
     * 批量删除邮箱发送记录
     * 
     * @param ids 需要删除的邮箱发送记录主键
     * @return 结果
     */
    @Override
    public int deleteZQEmailByIds(Long[] ids)
    {
        return zQEmailMapper.deleteZQEmailByIds(ids);
    }

    /**
     * 删除邮箱发送记录信息
     * 
     * @param id 邮箱发送记录主键
     * @return 结果
     */
    @Override
    public int deleteZQEmailById(Long id)
    {
        return zQEmailMapper.deleteZQEmailById(id);
    }

    @Override
    public ZQEmail getLastOne() {
        ZQEmail lastOne = zQEmailMapper.getLastOne(SecurityUtils.getUserId());
        if (Objects.isNull(lastOne)){
            return new ZQEmail();
        }
        return lastOne;
    }
}
